package com.shangxia.leetcode.greedyAlgorithm;

import lombok.extern.slf4j.Slf4j;

/**
 * @ProjectName: leetcode
 * @ClassName: CheckPossibility665
 * @Time: 2020/12/8
 * @Author: zhouy
 * @Description: 665. 非递减数列
 * @Experience:
 */

@Slf4j
public class CheckPossibility665 {

    public static void main(String[] args) {
        System.out.println(checkPossibility(new int[]{4, 2, 3}));
    }

    public static boolean checkPossibility(int[] nums) {
        int cnt = 0;
        for (int i = 1; i < nums.length && cnt <= 1; i++) {
            if (nums[i - 1] > nums[i]) {
                cnt++;
                if (i - 2 >= 0 && nums[i - 2] > nums[i]) {
                    nums[i] = nums[i - 1];
                }
            }
        }
        return cnt <= 1;
    }
}
